""" 塔 """
import pygame
from pygame.sprite import Sprite


class Tower(Sprite):
    def __init__(self, screen, pysettings, x, y):
        super(Tower, self).__init__()
        self.image = pygame.image.load("./image/tower.gif")
        self.rect = self.image.get_rect()
        
        self.screen = screen
        self.rect.x = x
        self.rect.y = y+self.rect.height
        self.settings = pysettings
        # 当前的方块
        self.items = []
        
    def draw_tower(self):
        """ 绘制塔"""
        self.screen.blit(self.image, self.rect)
     
    def addItem(self,item):
        """ 添加方块"""
        self.items.append(item)
    
    def remove(self,item):
        """ 去掉当前的方块"""
        self.items.remove(item)
        
    def getLastItem(self):
        """获取最上面一个条块"""
        if len(self.items) == 0:
            return None
        return self.items[-1]
        
    def getNextItemPosition(self, item):
        """ 获取条块位置"""
        posx = self.rect.x + (self.rect.width - item.width)/2
        posy = self.getNextItemPositionY()
        width = item.width
        height = item.height
        return posx, posy, width, height
    
    def getNextItemPositionY(self):
        """ 获取下一方块的Y"""
        return self.rect.height - (self.settings.item_height+3) * len(self.items)+165
    
    def getCurrentY(self, item):
        if item.getChoose():
            return self.rect.height - (self.settings.item_height+3) * (len(self.items)-1)+165
